home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
exampleCode
/
stencil
/
gameOfLife.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
104 lines
/*
* Copyright (C) 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* gameOfLife.c:
*
* Here is a program that plays the game of life by using stencil planes.
* The gl window does not watch for REDRAW events so if one pops/pushes
* other * windows on to/off of this window, the game becomes a bit more
* interesting...
*/
#include <gl.h>
#include <device.h>
#define DX 800
#define DY 800
#define DEADCOLOR 0
#define LIVECOLOR 0xffffffff
long xorg, yorg;
unsigned long pixbuf[DX][DY];
main()
{
long i, j;
if (getgdesc(GD_BITS_STENCIL) < 4) {
printf("requires 4 bits of stencil planes to run\n");
return;
}
prefsize(DX, DY);
winopen("game of life using stencil planes");
subpixel(TRUE);
getorigin(&xorg, &yorg);
stensize(4);
RGBmode();
gconfig();
zbuffer(TRUE);
czclear(0, 0);
zwritemask(0);
zfunction(ZF_NOTEQUAL);
sclear(0);
zbuffer(FALSE);
for (i = 0; i < DX; i++)
for (j = 0; j < DY; j++) pixbuf[i][j] = DEADCOLOR;
for (i = 40; i < DX-40; i++) pixbuf[DY/2][i] = LIVECOLOR;
lrectwrite(0, 0, DX-1, DY-1, (unsigned long *)pixbuf);
readsource(SRC_FRONT);
while(1) {
iteratelife();
}
}
readpix()
{
lrectread(0, 0, DX-1, DY-1, (unsigned long *)pixbuf);
}
writepix(long dx, long dy)
{
lrectwrite(dx, dy, dx+DX-1, dy+DY-1, (unsigned long *)pixbuf);
}
iteratelife()
{
readpix();
wmpack(0);
pixmode(PM_ZDATA, 1.0);
zbuffer(TRUE);
stencil(TRUE, 1, SF_ALWAYS, 0xf, ST_KEEP, ST_KEEP, ST_INCR);
writepix(-1, -1);
writepix(-1, 0);
writepix(-1, 1);
writepix(0, -1);
writepix(0, 1);
writepix(1, -1);
writepix(1, 0);
writepix(1, 1);
zbuffer(FALSE);
pixmode(PM_ZDATA, 0.0);
wmpack(0xffffffff);
cpack(LIVECOLOR);
stencil(TRUE, 3, SF_EQUAL, 0xf, ST_KEEP, ST_DECR, ST_DECR);
rectfi(0, 0, 10000, 10000);
stencil(TRUE, 2, SF_NOTEQUAL, 0xf, ST_ZERO, ST_ZERO, ST_ZERO);
cpack(DEADCOLOR);
rectfi(0, 0, 10000, 10000);
}